import org.jsoup.Jsoup
import org.jsoup.nodes.Document

binding1 = new Binding()
binding1.setProperty('name', 'lisi')
Document doc = Jsoup.connect("http://www.iciba.com/?=2016pcChromebookmark").get()
binding1.setProperty('doc', doc)
shell = new GroovyShell(binding1)
def script4 = shell.parse(new File('dsl_shell.txt').text)

//动态添加方法，使之执行
script4.getMetaClass().setProperty("map", new HashMap())
script4.getMetaClass().graber = { closure ->
    closure()
    map
}
script4.getMetaClass().set = {name, closure ->
    values = closure()
    name = name.trim()
    if(name.contains("_")) {
        String[] keys = name.split("_")
        for(i=0; i<keys.length; i++) {
            map.put(keys[i], values[i])
        }
    } else {
        map.put(name, values)
    }
}
script4.getMetaClass().$ = {cssSeletor ->
    doc.select(cssSeletor)
}

def result = script4.run()
println "println result: "
println result